<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-媒体资源录入页</title>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<link href="<%=path%>/js/My97DatePicker/skin/WdatePicker.css"
			rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="<%=path%>/js/My97DatePicker/WdatePicker.js"></script>
		<link type="text/css"
			href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css"
			rel="stylesheet" />
		<script type="text/javascript"
			src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
	
<style type="text/css">
.add_div {
	padding: 0px 0;
	border: 1px solid #0078b6;
}

.add_div .table_add {
	width: 100%;
}

.add_div .table_add tr {
	height: 40px;
}

.add_div .table_add th {
	padding: 0px 0;
	text-align: right;
	color: #000000;
	font-size: 14px;
}

.add_div .table_add td {
	padding: 0px 0;
}
</style>
<script type="text/javascript">
	$(document).ready(function(){  
   //禁止退格键 作用于Firefox、Opera    
    document.onkeypress = banBackSpace;  
   //禁止退格键 作用于IE、Chrome   
	  document.onkeydown = banBackSpace;  
	});
	//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外 
function banBackSpace(e){
	//alert(event.keyCode)
    var ev = e || window.event;//获取event对象   
    var obj = ev.target || ev.srcElement;//获取事件源     
    var t = obj.type || obj.getAttribute('type');//获取事件源类型     
    //获取作为判断条件的事件类型 
    var vReadOnly = obj.readOnly;
    var vDisabled = obj.disabled;
    //处理undefined值情况 
    vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
    vDisabled = (vDisabled == undefined) ? true : vDisabled;
    //当敲Backspace键时，事件源类型为密码或单行、多行文本的，  
    //并且readOnly属性为true或disabled属性为true的，则退格键失效  
    var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
    //当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效    
    var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
    //判断    
    if (flag2 || flag1) 
        event.returnValue = false;//这里如果写 return false 无法实现效果 
}
</script>
<script type="text/javascript">
	$(function(){
		$('#dialog').dialog({
			autoOpen: false,
			width: 400,
			height: 410,
			show: "blind",
			hide:"slide"
			//position: [800,220]  //显示位置
			//modal: true, overlay: { opacity: 0.5, background: "black" } ,	
		});
		$('#dialog_link').click(function(){
			$('#dialog').dialog('open');
			return false;
		})
	});
</script>

<script type="text/javascript">
	function xiangmuDBlclick(){
		$("#dialog_link").val($("#xiangmuId").val());
		document.getElementById("dialog_link").focus();
		var b = document.getElementById("xiangmuId").value;
		$.getJSON("findAllMediasummByIDAction!findAllMediasummByID.action?"+ new Date(),{contractID:b},function(data){
			$("input[name='mediaPrice.city']").val(data.contract.contractCity);//城市需要录入值
			$("#mediaPurchaseTypeHidden").val(data.contract.contractType);
			$.each(data.citylist,function(i,value){
				if(value.id == data.contract.contractCity){
					$("#city").val(value.datavalue); //显示的城市
				}
			});
			
			//$("#payModeId").val(data.contract.contractPayment); //付款方式
			$.each(data.payModeList,function(i,value){
				if(value.id == data.contract.contractPayment){
					$("#payModeName").val(value.datavalue); //显示的城市
				}
			});
			
			$.each(data.mediaPurchaseTypeList,function(i,value){
				if(value.id == data.contract.contractType){
					$("#mediaPurchaseType").val(value.datavalue); //统购类型
				}
			});
			
			$("#years").val(data.contract.contractYear); //签约年份
			$("#mediaStartTime").val(data.contract.contractStartTime.substring(0,10));//开始时间
			$("#mediaEndTime").val(data.contract.contractEndTime.substring(0,10));//结束时间
			if(data.contract.contractBType==1){
				$("#mediaProvider").val(data.contract.contractBName);//供应商
				document.getElementById("mediaProvider").readOnly= true;//供应商只读
				document.getElementById("mediaAgent").readOnly= true;//供应商只读
				$("#mediaAgent").val("");//代理商
			}
			if(data.contract.contractBType==2){
				$("#mediaProvider").val("");//供应商
				$("#mediaAgent").val(data.contract.contractBName);//代理商
				document.getElementById("mediaAgent").readOnly= true;//代理商只读
				document.getElementById("mediaProvider").readOnly= false;//供应商
			}
		});
		$("#dialog").dialog("close");
	}
	function findAllContract(){
		$.getJSON("findAllMediasummByNameAction!findAllMediasummByName.action?"+ new Date(),{contractName:$("#contractName").val()},function(data){
			//清空显示层中的数据
			$("#xiangmuId").html("");
			$.each(data.contractList,function(i,value){
				$("#xiangmuId").append($("<option value='" + value.contractID + "'>" + value.contractName + "</option>"));
			});
		});
	}
	
</script>

<script type="text/javascript">
//随单
//在id为test的table的最后增加一行    
function addSuiDan(id){
		var num = new RegExp("^[0-9]*$");
		var tr_id = $("#"+id+">tbody>tr:last").attr("id");
		//alert(tr_id);
		var tdValue=$("#suiDanShang"+tr_id).val(); //上次的上限值
		tr_id++; 
		//alert(tdValue+"_"+tr_id);
		if($.trim(tdValue) !=""){
		//alert($("#suiDanShang"+(tr_id-1)).val());
		//alert($("#suiDanXia"+(tr_id-1)).val());
		if(num.test($("#suiDanShang"+(tr_id-1)).val())){
		if(parseInt($("#suiDanShang"+(tr_id-1)).val()) - parseInt($("#suiDanXia"+(tr_id-1)).val()) > 0){
			document.getElementById("suiDanShang"+(tr_id-1)).readOnly= true;//当前上限值只读
			//$("#suiDanShang"+(tr_id-1)).attr("readonly":"readonly");
		
		var str = "<tr id = '"+tr_id+"'><td width='100%' style='padding-left:150px;'><b style='font-size:14px;color: black'>年投放量：<input name='suiDan_01' maxlength='5' id='suiDanXia"+tr_id+"' value='"+tdValue+"' type='text' class='text' style='text-align:center; color:#0078B6;' readonly='readonly'/>&nbsp;&nbsp;万&nbsp;-&nbsp;&nbsp;"+
				"<input type='text' maxlength='5' id='suiDanShang"+tr_id+"' name='suiDan_02' class='text' style='text-align:center; color:#0078B6;'/>&nbsp;&nbsp;万(包含)，优惠额度："+
				"<input type='text'name='suiDan_03' maxlength='10' class='text' style='text-align:center; color:#0078B6;' />&nbsp;</b></td></tr>";      
		$('#'+id).append(str);
		}else{
			alert("随单上限值不能小于或等于下限值！");
			document.getElementById("suiDanShang"+(tr_id-1)).focus();
		}
		}else{
			alert("随单上限值不是正整数！");
			document.getElementById("suiDanShang"+(tr_id-1)).focus();
		}
		}else{
			alert("随单上限值不能为空！");
			document.getElementById("suiDanShang"+(tr_id-1)).focus();
		}
	}    
//删除id为test的table的最后一行    
function delSuiDan(id){    
var tr_id = $("#"+id+">tbody>tr:last").attr("id");   
if(tr_id - 100 > 0){
	//alert(tr_id);
	$("#"+tr_id).remove();
	document.getElementById("suiDanShang"+(tr_id-1)).readOnly= false;//上一个上限值可输入
	$("#suiDanShang"+(tr_id-1)).val("");//清空上一个上限值
	document.getElementById("suiDanShang"+(tr_id-1)).focus();//获得上一个上限值焦点
	$("#"+tr_id).remove();
}else{
	alert("随单的最后一条，不可删除！");
}
}

//常规
function addChangGui(id){
var num = new RegExp("^[0-9]*$");
var tr_id = $("#"+id+">tbody>tr:last").attr("id");
//alert(tr_id);
var tdValue=$("#changGuiShang"+tr_id).val(); //上次的上限值
tr_id++; 
//alert(tdValue+"_"+tr_id);
if($.trim(tdValue) !=""){
//alert($("#suiDanShang"+(tr_id-1)).val());
//alert($("#suiDanXia"+(tr_id-1)).val());
if(num.test($("#changGuiShang"+(tr_id-1)).val())){
if(parseInt($("#changGuiShang"+(tr_id-1)).val()) - parseInt($("#changGuiXia"+(tr_id-1)).val()) > 0){
	document.getElementById("changGuiShang"+(tr_id-1)).readOnly= true;//当前上限值只读
	//$("#changGuiShang"+(tr_id-1)).attr("readonly":"readonly");

var str = "<tr id = '"+tr_id+"'><td width='100%' style='padding-left:150px;'><b style='font-size:14px;color: black'>年投放量：<input name='changGui_01' maxlength='5' id='changGuiXia"+tr_id+"' value='"+tdValue+"' type='text' class='text' style='text-align:center; color:#0078B6;' readonly='readonly'/>&nbsp;&nbsp;万&nbsp;-&nbsp;&nbsp;"+
		"<input type='text' id='changGuiShang"+tr_id+"' name='changGui_02' maxlength='5' class='text' style='text-align:center; color:#0078B6;'/>&nbsp;&nbsp;万(包含)，优惠额度："+
		"<input type='text'name='changGui_03' maxlength='10' class='text' style='text-align:center; color:#0078B6;' />&nbsp;</b></td></tr>";      
$('#'+id).append(str);
}else{
			alert("常规上限值不能小于或等于下限值！");
			document.getElementById("changGuiShang"+(tr_id-1)).focus();
		}
		}else{
			alert("常规上限值不是正整数！");
			document.getElementById("changGuiShang"+(tr_id-1)).focus();
		}
		}else{
			alert("常规上限值不能为空！");
			document.getElementById("changGuiShang"+(tr_id-1)).focus();
		}
}    
//删除id为test的table的最后一行    
function delChangGui(id){    
var tr_id = $("#"+id+">tbody>tr:last").attr("id");
if(tr_id - 200 > 0){
	$('#'+tr_id).remove();
	document.getElementById("changGuiShang"+(tr_id-1)).readOnly= false;//上一个上限值可输入    
	$("#changGuiShang"+(tr_id-1)).val("");//清空上一个上限值
	document.getElementById("changGuiShang"+(tr_id-1)).focus();//获得上一个上限值焦点
}else{
	alert("常规的最后一条，不可删除！");
}
} 

//返还
function addFanHuan(id){  
var num = new RegExp("^[0-9]*$");  
var tr_id = $("#"+id+">tbody>tr:last").attr("id");
//alert(tr_id);
var tdValue=$("#fanHuanShang"+tr_id).val(); //上次的上限值
tr_id++; 
//alert(tdValue+"_"+tr_id);
if($.trim(tdValue) !=""){
//alert($("#suiDanShang"+(tr_id-1)).val());
//alert($("#suiDanXia"+(tr_id-1)).val());
if(num.test($("#fanHuanShang"+(tr_id-1)).val())){
if(parseInt($("#fanHuanShang"+(tr_id-1)).val()) - parseInt($("#fanHuanXia"+(tr_id-1)).val()) > 0){
	document.getElementById("fanHuanShang"+(tr_id-1)).readOnly= true;//当前上限值只读
	//$("#fanHuanShang"+(tr_id-1)).attr("readonly":"readonly");
var str = "<tr id = '"+tr_id+"'><td width='100%' style='padding-left:175px;'><b style='font-size:14px;color: black'>年投放量：<input name='fanHuan_01' maxlength='5' id='fanHuanXia"+tr_id+"' value='"+tdValue+"' type='text' class='text' style='text-align:center; color:#0078B6;' readonly='readonly'/>&nbsp;&nbsp;万&nbsp;-&nbsp;&nbsp;"+
		"<input type='text' id='fanHuanShang"+tr_id+"' maxlength='5' name='fanHuan_02' class='text' style='text-align:center; color:#0078B6;'/>&nbsp;&nbsp;万(包含)，优惠额度："+
		"<input type='text'name='fanHuan_03' maxlength='10' class='text' style='text-align:center; color:#0078B6;' />&nbsp;</b></td></tr>";      
$('#'+id).append(str);
}else{
			alert("返还上限值不能小于或等于下限值！");
			document.getElementById("fanHuanShang"+(tr_id-1)).focus();
		}
		}else{
			alert("返还上限值不是正整数！");
			document.getElementById("fanHuanShang"+(tr_id-1)).focus();
		}
		}else{
			alert("返还上限值不能为空！");
			document.getElementById("fanHuanShang"+(tr_id-1)).focus();
		}
}    
//删除id为test的table的最后一行    
function delFanHuan(id){    
var tr_id = $("#"+id+">tbody>tr:last").attr("id");   
if(tr_id - 400 > 0){
	$('#'+tr_id).remove();
	document.getElementById("fanHuanShang"+(tr_id-1)).readOnly= false;//上一个上限值可输入    
	$("#fanHuanShang"+(tr_id-1)).val("");//清空上一个上限值
	document.getElementById("fanHuanShang"+(tr_id-1)).focus();//获得上一个上限值焦点
}else{
	alert("返还的最后一条，不可删除！");
}
} 
</script>

<script type="text/javascript">
	function trim(str) { //去掉空格
	var str1 = $.trim(str);
	return str1;
	}
	function getLen(str){
		var len=0;
		if(null!=str&&str!=""){
			for(var i=0;i<str.length;i++){
				var intCode=str.charCodeAt(i);
				//如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
				if (intCode>=0&&intCode<=127&&intCode!=34&&intCode!=39&&intCode!=47&&intCode!=60&&intCode!=62&&intCode!=92){
					len=len+1;
				}else{
					len=len+3;
				}
			}
		}
		return len;
	}
	function doAddMediaPrice(url){
		var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
		var contractNum = /^[\w-\s]+$/;
		var msgName = "0";
		var mediaNameTip = $.trim($("#mediaName").val());//媒体名称
       if (mediaNameTip == '') {
		alert('媒体名称不能为空！');
			document.getElementById('mediaName').focus();
			return false;
		}
		
		if (!myReg.test(mediaNameTip)) {
			alert("媒体名称不能包含：“$、#、%、/、*、<、>、'、\"、\\、& ”等特殊字符，请重新输入！");
			document.getElementById('mediaName').focus();
			return false;
		}
		
		if (getLen(mediaNameTip) > 150) {
			alert("媒体名称应不大于50个汉字(150个字符)！");
			document.getElementById('mediaName').focus();
			return false;
		}
		var url1 = encodeURI(encodeURI('findMediaPriceBymediaNameAction.action?'+new Date()+'&mediaName=' + $.trim(mediaNameTip)));
       $.ajax({
               	url:url1,
               	async:false,
               	datatype: "json",
               	error : function() {   
			    	alert('服务器异常！');
			    	window.location.href="toErrorAction.action";
				},  
               	success : function(data) { 
            		if(data.message =="error"){
						alert("媒体名称重复！");
						document.getElementById("mediaName").focus();
						msgName = "1";
						return false;
					}
					if(data.message =="success"){
						msgName = "2";
					}
         }    
       }); 
		
		var dialog_linkTip = $.trim($("#dialog_link").val());//合同编号
		if(dialog_linkTip == ""){
			alert("合同编号不能为空！");
			document.getElementById("dialog_link").focus();
			return false;
		}
		
		var mediaDescription = $.trim($("#mediaDescription").val());
		if(getLen(mediaDescription)>240){
			alert("媒体简介长度不能大于80个汉字(240个字符)！");
			document.getElementById("mediaDescription").focus();
			return false;
		}
		
		
		var num = new RegExp("^[0-9]*$");
		var pattern = /[^\d\.]/g;
		var suiDan_01='';
		var suiDan_02 = '';
		var suiDan_03 = '';
		
		var changGui_01='';
		var changGui_02 = '';
		var changGui_03 = '';
		
		var fanHuan_01='';
		var fanHuan_02 = '';
		var fanHuan_03 = '';
		var msgAlert = "0";//正确
		
			$("#levelLowerLimit_01").val("");//随单下限值
			$("#levelUpperLimit_01").val("");//随单上限值
			$("#levelDiscount_01").val("");//随单额度
			$("#levelLowerLimit_02").val("");//常规下限值
			$("#levelUpperLimit_02").val("");//常规上限值
			$("#levelDiscount_02").val("");//常规额度
			$("#levelLowerLimit_03").val("");//返还下限值
			$("#levelUpperLimit_03").val("");//返还上限值
			$("#levelDiscount_03").val("");//返还额度
		
		if(document.getElementById("checkbox_01").checked){
			$("input[type='text'][name='suiDan_01']", document.forms[0]).each(function(){
				suiDan_01 += ","+$(this).val();
			}); 
			$("input[type='text'][name='suiDan_02']", document.forms[0]).each(function(){
				if($(this).val()==""){
					suiDan_02 += ","+(parseInt(0));
				}else{
					suiDan_02 += ","+$(this).val();
				}
			}); 
			$("input[type='text'][name='suiDan_03']", document.forms[0]).each(function(){
				suiDan_03 += ","+$(this).val();
			}); 
			//判断上限值文本框值
			var str_suiDan = suiDan_02.substring(1);
			var arr_suiDan = str_suiDan.split(",");
			var str_suiDan01 = suiDan_01.substring(1);//截取下限值
			var arr_suiDan01 = str_suiDan01.split(",");
			var arr_suiDan01Length = arr_suiDan01.length;//下限长度
			var str_suiDan_001 = arr_suiDan01[arr_suiDan01Length-1];//最后下限值
            var str_suiDan_002 = arr_suiDan[arr_suiDan01Length-1];//最后上限值
			if(trim(str_suiDan_002) == "0"){
				
			}else if(!num.test(trim(str_suiDan_002))){
				alert("随单上限值不是整数！");
				msgAlert ="1";  
			}else if(str_suiDan_002 - str_suiDan_001 <=0){//最后上限值不能<=最后上限值
					alert("随单上限值不能小于或等于下限值！");
					msgAlert ="1";  
				}
			
			//判断最后文本框值
			var str_1 = suiDan_03.substring(1);
			var arr = str_1.split(",");
			for(var i=0; i<arr.length;i++){
				if($.trim(arr[i])==""){     
					 alert("随单优惠额度不能为空！");
					 msgAlert ="1";
					 break;
				}else {
                  if(/^(\+|-)?\d+($|\.\d+$)/.test(arr[i])) {
                    var value=parseInt(arr[i]);
                    var val=$('input:radio[name="suiDanSaleType"]:checked').val(); 
                    if(val == 1){
                    	if(value>=0&&value<=100){
	                    }else{
	                         alert("随单优惠额度应该是0-100的数！");
	                         msgAlert ="1";
	                        break;  
	                    }      
                    }
                   }else{
                    alert("随单优惠额度应该是数字！");
                    msgAlert ="1";  
					break;
                  }      
				}
			}
			
			$("#levelLowerLimit_01").val(suiDan_01.substring(1));//随单下限值
			$("#levelUpperLimit_01").val(suiDan_02.substring(1,suiDan_02.length));//随单上限值
			$("#levelDiscount_01").val(suiDan_03.substring(1));//随单优惠额度
		}
		if(document.getElementById("checkbox_02").checked){
			$("input[type='text'][name='changGui_01']", document.forms[0]).each(function(){
				changGui_01 += ","+$(this).val();
			}); 
			$("input[type='text'][name='changGui_02']", document.forms[0]).each(function(){
				if($(this).val()==""){
					changGui_02 += ","+(parseInt(0));
				}else{
					changGui_02 += ","+$(this).val();
				}
			}); 
			$("input[type='text'][name='changGui_03']", document.forms[0]).each(function(){
			changGui_03 += ","+$(this).val();
			
			}); 
			
			//判断上限文本框值
			var str_changGui = changGui_02.substring(1);
			var arr_changGui = str_changGui.split(",");
			var str_changGui01 = changGui_01.substring(1);//截取下限值
			var arr_changGui01 = str_changGui01.split(",");
			var arr_changGui01Length = arr_changGui01.length;//下限长度
			var str_changGui_001 = arr_changGui01[arr_changGui01Length-1];//最后下限值
            var str_changGui_002 = arr_changGui[arr_changGui01Length-1];//最后上限值
			if(trim(str_changGui_002) == "0"){
			}else if(!num.test(trim(str_changGui_002))){
				alert("常规上限值不是整数！");
				msgAlert ="1";  
			}else if(str_changGui_002 - str_changGui_001 <=0){//最后上限值不能<=最后上限值
					alert("常规上限值不能小于或等于下限值！");
					msgAlert ="1";  
				}
			//判断最后文本框值
			var str_1 = changGui_03.substring(1);
			var arr = str_1.split(",");
			for(var i=0; i<arr.length;i++){
				if(arr[i]==""){     
					 alert("常规优惠额度不能为空！");
					 msgAlert ="1";
					 break;
				}else {
                  if(/^(\+|-)?\d+($|\.\d+$)/.test(arr[i])) {
                    var value=parseInt(arr[i]);
                    var val=$('input:radio[name="changGuiSaleType"]:checked').val(); 
                    if(val == 1){
                    	if(value>=0&&value<=100){
	                    }else{
	                         alert("常规优惠额度应该是0-100的数！");
	                         msgAlert ="1";
	                        break;  
	                    }      
                    }
                   }else{
                    alert("常规优惠额度应该是数字！");
                    msgAlert ="1";
					break;
                  }      
				}
			}
			
			$("#levelLowerLimit_02").val(changGui_01.substring(1));//常规下限值
			$("#levelUpperLimit_02").val(changGui_02.substring(1,changGui_02.length));//常规上限值
			$("#levelDiscount_02").val(changGui_03.substring(1));//常规优惠额度
		}
		if(document.getElementById("checkbox_03").checked){
			if(document.getElementById("mediaDiscountType").value !=1){
			$("input[type='text'][name='fanHuan_01']", document.forms[0]).each(function(){
				fanHuan_01 += ","+$(this).val();
			}); 
			$("input[type='text'][name='fanHuan_02']", document.forms[0]).each(function(){
				if($(this).val()==""){
					fanHuan_02 += ","+(parseInt(0));
				}else{
					fanHuan_02 += ","+$(this).val();
				}
			}); 
			$("input[type='text'][name='fanHuan_03']", document.forms[0]).each(function(){
			//alert($(this).val())
			fanHuan_03 += ","+$(this).val();
			}); 
			
			//判断最后文本框值
			var str_1 = fanHuan_03.substring(1);
			var arr = str_1.split(",");
			for(var i=0; i<arr.length;i++){
				if(arr[i]==""){     
					 alert("返还优惠额度不能为空！");
					 msgAlert ="1";
					 break;
				}else {
                  if(/^(\+|-)?\d+($|\.\d+$)/.test(arr[i])) {
                    var value=parseInt(arr[i]);
                    if(value>=0&&value<=100){
                        
                    }else{
                         alert("返还优惠额度应该是0-100的数！");
                         msgAlert ="1";
                        break;  
                    }      
                   }else{
                    alert("返还优惠额度不是整数！");
                    msgAlert ="1";  
					break;
                  }      
				}
			}
			
			//判断上限文本框值
			var str_fanHuan = fanHuan_02.substring(1);
			var arr_fanHuan = str_fanHuan.split(",");
			var str_fanHuan01 = fanHuan_01.substring(1);
			var arr_fanHuan01 = str_fanHuan01.split(",");
			var arr_fanHuan01Length = arr_fanHuan01.length;
			var str_fanHuan_001 = arr_fanHuan01[arr_fanHuan01Length-1];
            var str_fanHuan_002 = arr_fanHuan[arr_fanHuan01Length-1];
			if(trim(str_fanHuan_002) == "0"){
			}else if(!num.test(trim(str_fanHuan_002))){
				alert("返还上限值不是整数！");
				msgAlert ="1";  
			}else if(str_fanHuan_002 - str_fanHuan_001 <=0){
					alert("返还上限值不能小于或等于下限值！");
					msgAlert ="1";  
				}
			
			$("#levelLowerLimit_03").val(fanHuan_01.substring(1));//返还下限值
			$("#levelUpperLimit_03").val(fanHuan_02.substring(1,fanHuan_02.length));//返还上限值
			$("#levelDiscount_03").val(fanHuan_03.substring(1));//返还优惠额度
		}else if(trim($("#eDuValue").val())==""){
				alert("返还优惠额度不能为空！");
				msgAlert ="1";
			}else if($("#eDuValue").val()>100 || $("#eDuValue").val()< 0){
				alert("返还优惠额度是0-100数！");
				msgAlert ="1";
			}else if(pattern.test(trim($("#eDuValue").val()))){
				alert("返还优惠额度不是整数！");
				msgAlert ="1";
			}
		
		}
		
		if(msgName == "2" && msgAlert =="0"){
			var mediaName_001 = $.trim($("#mediaName").val());
			$("#mediaName").val(mediaName_001);
			document.forms[0].action=url;
			document.forms[0].submit();
		}
	}
</script>
<script type="text/javascript">
	function checkboxClick(){
		if(document.getElementById("checkbox_01").checked){
			$("#suiDanDiv").show();
		}else{
			$("#suiDanDiv").hide();
		}
		if(document.getElementById("checkbox_02").checked){
			$("#changGuiDiv").show();
		}else{
			$("#changGuiDiv").hide();
		}
		if(document.getElementById("checkbox_03").checked){
			$("#hanHuaiDiv").show();
		}else{
			$("#hanHuaiDiv").hide();
		}
	}
	
	function rewlset(){
		$("#contractName").val("");
	}
	function doQuXiao(){
		if(confirm('您确认取消本次操作？')){
			window.location.href='mediaPriceAction.action?currentPage=1';
		}
	}
</script>
<script type="text/javascript">
	function zheKouSelect_01(){
		var mediaDiscountType = $("#mediaDiscountType").val();
		if(mediaDiscountType ==1){
			$("#fanhuaiBtnDiv").hide();			
			var html ="<br/><b style='font-size:14px;color:black;padding-left:178px;'>优惠额度：<input type='text' maxlength='5' class='text' id='eDuValue' name='eDuValue' style='text-align: center; color: #0078B6;' />&nbsp;%</b><br/><br/>";
			$("#zheKouDivID").html(html);
		}else{
			//替换
			var html = "";
			html += "<table id='fanHuan_Tab' cellpadding='4' cellspacing='4' width='100%'>";
			html += "<tr id='400'><td width='100%' style='padding-left: 175px;'>";
			html +="<b style='font-size:14px;color: black'>年投放量：<input name='fanHuan_01' maxlength='5' type='text' class='text' id='fanHuanXia400' style='text-align: center; color: #0078B6;' value='0' readonly='readonly' />";
			html+= "&nbsp; 万&nbsp;-&nbsp; <input type='text' class='text' maxlength='5' name='fanHuan_02' id='fanHuanShang400' style='text-align: center; color: #0078B6;' />";
			html+="&nbsp; 万(包含)，优惠额度：<input type='text' maxlength='10' class='text' name='fanHuan_03' style='text-align: center; color: #0078B6;' />&nbsp;";
			html+="</b></td></tr></table>";
			$("#fanhuaiBtnDiv").show();	
			$("#zheKouDivID").html(html);
		}
	}
</script>
<script type="text/javascript">
	//$(function(){
        //selectNav('nav2');
    //});
    function doSubmit(url){
    	document.forms[0].action=url;
		document.forms[0].submit();
    }
</script>

</head>

<body>
<!-- 顶栏start -->
<jsp:include page="../common/top.jsp"></jsp:include>
<!-- 顶部end -->

<!-- 顶部start -->
<div id="main">
	<div class="body">
	<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<form action="" method="post" id="form1">
				<div id='tempDiv'></div>
					<input type="hidden" id="levelLowerLimit_01"
						name="levelLowerLimit_01" />
					<input type="hidden" id="levelUpperLimit_01"
						name="levelUpperLimit_01" />
					<input type="hidden" id="levelDiscount_01" name="levelDiscount_01" />

					<input type="hidden" id="levelLowerLimit_02"
						name="levelLowerLimit_02" />
					<input type="hidden" id="levelUpperLimit_02"
						name="levelUpperLimit_02" />
					<input type="hidden" id="levelDiscount_02" name="levelDiscount_02" />

					<input type="hidden" id="levelLowerLimit_03"
						name="levelLowerLimit_03" />
					<input type="hidden" id="levelUpperLimit_03"
						name="levelUpperLimit_03" />
					<input type="hidden" id="levelDiscount_03" name="levelDiscount_03" />
					<div class="main_body">
						
						<div class="add_div">
							<div class="add_div"
								style="border-top-style: none; border-left-style: none; border-right-style: none;">
								<table style="width: 100%;" cellpadding="0" cellspacing="0">
									<tr style="height: 30px; font-size: 16px; color: #000000; background:url(<%=path%>/images/banners30.jpg) repeat;">
										<td style="padding-left: 30px;">
											<b>媒体基本信息</b>
										</td>
									</tr>
								</table>
							</div>
							<table class="table_add" style="width: 100%;">
								<tr>
									<th width="325">
										媒体名称：
									</th>
									<td width="250">
										<input name="mediasumm.mediaName" id="mediaName" type="text"
											class="text" style="width: 200px;" maxlength="150"/>&nbsp;<span style="color:red">*</span>
									</td>
									<td width="100" >
										&nbsp;
									</td>
									<th  style="width: 250px;">
										媒体类型：
									</th>
									<td width="220">
										<s:select name="mediasumm.mediaType" list="mediaTypeList"
												listKey="id" listValue="datavalue" cssStyle="width:202px;">
										</s:select>
									</td>
									<td width="245">
										&nbsp;
									</td>
								</tr>
								<tr>
									<th>
										合同编号：
										
									</th>
									<td>
										<input name="mediaPrice.contractID" type="text" class="text"
											id="dialog_link" style="width: 200px;" value="" readonly="readonly"/>
											<span style="color:red">*</span>
									</td>
									<td>
										&nbsp;
									</td>
									<th>
										媒体归属：
									</th>
									<td width="220">
										<s:select name="mediaPrice.mediaBelog" list="mediaBelogList"
											listKey="id" listValue="datavalue" cssStyle="width:202px;">
										</s:select>
									</td>
									<td>
										&nbsp;
									</td>
								</tr>
								<tr>
									<th>
										供应商：
									</th>
									<td>
										<input name="mediasumm.mediaProvider" type="text"
											id="mediaProvider" class="text" style="width: 200px;" maxlength="30" readonly="readonly"/>
									</td>
									<td>
										&nbsp;
									</td>
									<th>
										代理商：
									</th>
									<td>
										<input name="mediaPrice.mediaAgent" type="text"
											id="mediaAgent" class="text" style="width: 200px;" maxlength="30" readonly="readonly"/>
									</td>
									<td>
										&nbsp;
									</td>
								</tr>
								<tr>
									<th>
										签约年份：
									</th>
									<td>
										<input name="mediaPrice.contractYear" id="years" type="text"
											class="text" style="width: 200px;" readonly="readonly" />
									</td>
									<td>
										&nbsp;
									</td>
									<th>
										归属地市：
									</th>
									<td>
										<input id="city" type="text" class="text"
											style="width: 200px;" readonly="readonly" />
										<input name="mediaPrice.city" type="hidden"
											readonly="readonly" />
									</td>
									<td>
										&nbsp;
									</td>
								</tr>
								<tr>
									<th>
										付款方式：
									</th>
									<td>
										<input readonly="readonly" type="text" class="text" id="payModeName" style="width: 200px"/>
										<!-- 
										<input readonly="readonly" type="text" class="text"  name="mediaPrice.payMode" id="payModeId" style="width: 200px"/>
										 -->
									</td>
									<td>
										&nbsp;
									</td>
									<th>
										媒体统购类型：
									</th>
									<td>
									<!-- 
										<s:select name="mediaPrice.mediaPurchaseType"
											list="mediaPurchaseTypeList" listKey="id"
											listValue="datavalue" cssStyle="width:202px;">
										</s:select>
										 -->
										<input type="text" readonly="readonly" id="mediaPurchaseType" class="text" style="width: 200px;"/>
										<input type="hidden" name="mediaPrice.mediaPurchaseType" id="mediaPurchaseTypeHidden"/>
									</td>
									<td>
										&nbsp;
									</td>
									
								</tr>
								<!-- 
								<tr>
									<th>
										阶梯计算周期：
									</th>
									<td>
										<s:select
											name="mediaPrice.levelCalculatePeriod"
											list="levelCalculatePeriodList" listKey="id"
											listValue="datavalue" cssStyle="width:202px;">
										</s:select>
									</td>
									<td>
										&nbsp;
									</td>
									<th>
										当前阶梯计算日：
									</th>
									<td>
										<input id="lastCalculateDate"
											name="mediaPrice.lastCalculateDate" type="text"
											class="text Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})" 
											style="width: 200px;" value="${mediaPrice.mediaEndTime}" />
									<td>
										&nbsp;
									</td>
								</tr>
								 -->
								<tr>
									<th>
										开始时间：
									</th>
									<td>
										<input name="mediaPrice.mediaStartTime" id="mediaStartTime"
											class="text" type="text" style="width: 200px;"  
											readonly="readonly" />
									<td>
										&nbsp;
									</td>
									<th>
										截止时间：
									</th>
									<td>
										<input name="mediaPrice.mediaEndTime" id="mediaEndTime"
											class="text" type="text"
											style="width: 200px;" 
											readonly="readonly" />
									<td>
										&nbsp;
									</td>
								</tr>
								<tr>
									<th>
										媒体资源类型：
									</th>
									<td>
										<s:select name="mediaPrice.mediaResourceType"
											list="mediaResourceTypeList" listKey="id"
											listValue="datavalue" cssStyle="width:202px;">
										</s:select>
									</td>
									<td>
										&nbsp;
									</td>
									<th>
										媒体折扣类型：
									</th>
									<td>
										<s:select id="mediaDiscountType"
											name="mediaPrice.mediaDiscountType"
											list="mediaDiscountTypeList" listKey="id"
											listValue="datavalue" cssStyle="width:202px;" onchange="zheKouSelect_01();">
										</s:select>
									</td>
									<td>
										&nbsp;
									</td>
								</tr>
									<tr>
									<th>
										媒体简介：
									</th>
									<td colspan="5">
										<textarea id="mediaDescription" name="mediasumm.mediaDescription" 
										style="width: 647px; font-family: '微软雅黑'; font-size: 12px; font-weight: bold; color: #666666;text-align: left;"></textarea>
									</td>
								</tr>
								<tr>
									<th>
										优惠方式：
									</th>
									<th colspan="5" style="text-align: left;">
										<input id="checkbox_01" type="checkbox" checked="checked"
											onclick="checkboxClick();" />
										&nbsp;&nbsp;随单赠送 &nbsp;&nbsp;&nbsp;&nbsp;
										<input id="checkbox_02" type="checkbox"
											onclick="checkboxClick();" />
										&nbsp;&nbsp;常规赠送 &nbsp;&nbsp;&nbsp;&nbsp;
										<input id="checkbox_03" type="checkbox"
											onclick="checkboxClick();" />
										&nbsp;&nbsp;返还赠送
									</th>
								</tr>
							</table>

							<div id="suiDanDiv">
								<div class="add_div"
									style="border-left-style: none; border-right-style: none;">
									<table style="width: 100%;" cellpadding="0" cellspacing="0">
										<tr
											style="height: 30px; font-size: 16px; color: #000000; background: url(<%=path%>/images/banners30.jpg) repeat;">
											<td style="padding-left: 30px;">
												<b>随单赠送</b>&nbsp;&nbsp;&nbsp;
													<input type="button" value="新增" onclick="addSuiDan('suiDan_Tab');" />&nbsp;
													<input type="button" value="删除" onclick="delSuiDan('suiDan_Tab');" />
											</td>
										</tr>
									</table>
								</div>
								<table class="table_add" width="100%">
									<tr>
									<th style="width: 300px;">
										是否累计：
									</th>
									<td width="200">
										<select 
											name="mediaPrice.promotionAAccumulat" style="width:200px;">
											<option value="1">
												是
											</option>
											<option value="2">
												否
											</option>
										</select>
									</td>
									<td width="150">&nbsp;</td>
									<th style="width:250px;">
										时间是否可调：
									</th>
									<td>
										<select 
											name="mediaPrice.promotionAValidDateAdjustable" style="width:200px;">
											<option value="1">
												是
											</option>
											<option value="2">
												否
											</option>
										</select>
									</td>
									<td width="255">&nbsp;</td>
									</tr>
									<tr>
									<th>
										赠送类型：
									</th>
									<td>
										<s:select name="mediaPrice.promotionAType"
											list="promotionATypeList" listKey="id"
											listValue="datavalue" cssStyle="width:200px;">
										</s:select>
									</td>
									<td>&nbsp;</td>
									<th>
										&nbsp;
									</th>
									<td>
										<input id="promotionALastValidDate"
											name="mediaPrice.promotionALastValidDate" type="hidden"
											class="text Wdate"
											onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})"
											 value="${mediaPrice.mediaEndTime}"
											readonly="readonly" style="width:196px;"/>
									</td>
									<td></td>
								</tr>
								<tr>
									<th>
										优惠类型：
									</th>
									<td colspan="5">
										<b style="font-size:13px;color: black">
											<s:radio list="#{'1':'折扣','2':'金额'}" id="saleType_01" name="suiDanSaleType" value="1"/>&nbsp;(元)
										</b>
									</td>
								</tr>
								</table>
								<div style="padding-left: 25px;">
								<table border="0" id="suiDan_Tab" cellpadding="6"
									cellspacing="6" width="100%">
									<tr id="100">
										<td width="100%" style='padding-left:150px;'>
											<b style="font-size:14px;color: black">年投放量：<input name="suiDan_01" type="text" maxlength='5' class="text" 
													id="suiDanXia100"
													style="text-align: center; color: #0078B6;"
													value="0" readonly="readonly" /> &nbsp;万&nbsp;-&nbsp; <input 
													type="text" class="text" name="suiDan_02" id="suiDanShang100" maxlength='5'
													style="text-align: center; color: #0078B6;" />&nbsp;
												万(包含)，优惠额度：<input type="text" class="text"
													name="suiDan_03" maxlength='10'
													style="text-align: center; color: #0078B6;" />&nbsp;
											</b>
											</td>
									</tr>
								</table>
								</div>
							</div>
							<div id="changGuiDiv" style="display: none;">
								<div class="add_div"
									style="border-left-style: none; border-right-style: none;">
									<table width="100%">
										<tr
											style="height: 30px; font-size: 16px; color: #000000; background: url(<%=path%>/images/banners30.jpg) repeat;">
											<td style="padding-left: 30px;">
												<b>常规赠送</b>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="新增" onclick="addChangGui('changGui_Tab');" />&nbsp;
												<input type="button" value="删除" onclick="delChangGui('changGui_Tab');" />
											</td>
										</tr>
									</table>
								</div>
								<table class="table_add" width="100%">
									<tr>
									<th style="width: 300px;">
										是否累计：
									</th>
									<td width="200">
										<select 
											name="mediaPrice.promotionBAccumulate" style="width: 200px;">
											<option value="1">
												是
											</option>
											<option value="2">
												否
											</option>
										</select>
									</td>
									<td width="150">&nbsp;</td>
									<th style="width:250px;">
										时间是否可调：
									</th>
									<td>
										<select 
											name="mediaPrice.promotionBValidDateAdjustable" style="width: 200px;">
											<option value="1">
												是
											</option>
											<option value="2">
												否
											</option>
										</select>
									</td>
									<td width="250">&nbsp;</td>
									</tr>
									<tr>
									<th>
										赠送类型：
									</th>
									<td>
										<s:select name="mediaPrice.promotionBType"
											list="promotionATypeList" listKey="id"
											listValue="datavalue" cssStyle="width:200px;">
										</s:select>
									</td>
									<td>&nbsp;</td>
									<th>
										&nbsp;
									</th>
									<td>
										<input id="promotionBLastValidDate"
											name="mediaPrice.promotionBLastValidDate" type="hidden"
											class="text Wdate" style="width: 196px;" 
											onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})"
											 value="${mediaPrice.mediaEndTime}"
											readonly="readonly" />
									</td>
									<td></td>
								</tr>
								<tr>
									<th>
										优惠类型：
									</th>
									<td colspan="5">
										<b style="font-size:13px;color: black">
											<s:radio list="#{'1':'折扣','2':'金额'}" id="saleType_02" name="changGuiSaleType" value="1"/>&nbsp;(元)
										</b>
									</td>
								</tr>
								
								</table>	
								<div style="padding-left: 30px;">
									
								<table border="0" id="changGui_Tab" cellpadding="4" cellspacing="4" width="100%">
									<tr id="200">
										<td width="100%" style='padding-left:150px;'>
											<b style='font-size:14px;color: black'>年投放量：<input name="changGui_01"
													type="text" id="changGuiXia200" class="text" maxlength='5'
													style="text-align: center; color: #0078B6;"
													value="0" readonly="readonly" /> &nbsp;万&nbsp;-&nbsp; <input
													type="text" class="text" name="changGui_02"
													id="changGuiShang200" maxlength='5'
													style="text-align: center; color: #0078B6;" />&nbsp;
												万(包含)，优惠额度：<input type="text" class="text"
													name="changGui_03" maxlength='10'
													style="text-align: center; color: #0078B6;" />&nbsp;
											</b>
									</td>
									</tr>
								</table>
								</div>
							</div>
							<div id="hanHuaiDiv" style="display: none;">
								<div class="add_div"
									style="border-left-style: none; border-right-style: none;">
									<table style="width: 100%;" cellpadding="0" cellspacing="0">
										<tr
											style="height: 30px; font-size: 16px; color: #000000; background: url(<%=path%>/images/banners30.jpg) repeat;">
											<td style="padding-left: 30px;">
												<b>返还赠送</b>
												<span id="fanhuaiBtnDiv" style="display: none;">
												&nbsp;&nbsp;&nbsp;<input type='button' value='新增' onclick="addFanHuan('fanHuan_Tab')"/>
												&nbsp;<input type='button' value='删除' onclick="delFanHuan('fanHuan_Tab')"/>
												</span>
											</td>
										</tr>
									</table>
								</div>
								
								<table class="table_add" width="100%">
								<tr>
									<th style="width: 300px;">
										时间是否可调：
									</th>
									<td width="200">
										<select 
											name="mediaPrice.promotionCValidDateAdjustable" style="width: 200px;">
											<option value="1">
												是
											</option>
											<option value="2">
												否
											</option>
										</select>
									</td>
									<td width="150">&nbsp;</td>
									<th style="width:250px;">
										赠送类型：
									</th>
									<td>
										<s:select name="mediaPrice.promotionCType"
											list="promotionATypeList" listKey="id"
											listValue="datavalue" cssStyle="width:200px;">
										</s:select>
									</td>
									<td width="250">
										<input id="promotionCLastValidDate"
											name="mediaPrice.promotionCLastValidDate" type="hidden"
											class="text Wdate" style="width: 196px;" 
											onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})"
											value="${mediaPrice.mediaEndTime}"
											readonly="readonly" />
									</td>
									</tr>
								</table>
								
								<div id="zheKouDivID">
									<b style='font-size:14px;color: black;padding-left: 178px;'>优惠额度：
										<input type='text' class='text' id='eDuValue' name='eDuValue' style='text-align: center; color: #0078B6;' maxlength="5"/>&nbsp;%
									</b>
								<br/><br/>
								<!-- 
									<input type="button" value="add"
									onclick="addFanHuan('fanHuan_Tab');" />
								<input type="button" value="del"
									onclick="delFanHuan('fanHuan_Tab');" />
								<table id="fanHuan_Tab" cellpadding="4" cellspacing="4" width="52%">
									<tr id="1">
										<td width="30%">
											<b style='font-size:13px;color: black'>年投放量： &nbsp;&nbsp; <input name="fanHuan_01"
													type="text" id="fanHuanXia1"
													style="width: 50px; text-align: center; color: #0078B6;"
													value="0" readonly="readonly" /> &nbsp;万&nbsp;-&nbsp; <input
													type="text" class="text" name="fanHuan_02"
													id="fanHuanShang1"
													style="width: 50px; text-align: center; color: #0078B6;" />&nbsp;
												万(包含)，优惠额度：<input type="text" class="text"
													name="fanHuan_03"
													style="width: 50px; text-align: center; color: #0078B6;" />&nbsp;
											</b>
											</td>
									</tr>
								</table>
								 -->
								</div>
							</div>
						</div>

						<div style="margin: 8px 0 0 150px;">
							<input type="button" onclick="return doAddMediaPrice('doAddMediaPriceAction.action?falg=1');" class="btn-title" value="保存并录入刊例信息"/>
							&nbsp;&nbsp;
							<input onclick="return doAddMediaPrice('doAddMediaPriceAction.action?falg=2');" type="button" class="btn-title" value="保存" />
							&nbsp;&nbsp;
							<input type="button" class="btn-title" value="取消"
								onclick="doQuXiao();" />
						</div>
					</div>
					<div id="dialog" title="合同名称列表" style="display: block;">
						<table width="0" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<input type="text" style="width: 250px" id="contractName"
										class="text" />
									&nbsp;
									<input type="button" class="btn-title" value="搜索"
										onclick="findAllContract();" />&nbsp;
									<input type="button" class="btn-title" value="重置"
										onclick="rewlset();" />	
								</td>
							</tr>
							<tr>
								<td style="padding-top: 5px;">
									<select id="xiangmuId" multiple="multiple"
										style="width: 100%; height: 335px;overflow:hidden"
										ondblclick="xiangmuDBlclick();">
										<s:iterator id="c" value="contractList">
											<option title="${c.contractName}" value="${c.contractID}">
												${c.contractName}
											</option>
										</s:iterator>
									</select>
								</td>
							</tr>
						</table>
					</div>
				</form>
				<!-- 顶部end -->

			</div>
		</div>
				<!-- 底部start -->
				<div id="bottom">
					<div class="body">
						<label>
							版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
						</label>
					</div>
				</div>
				<!-- 底部end -->
	</body>
</html>
